#ifndef QX_HW_SPI_H
#define QX_HW_SPI_H

#include <rtthread.h>
#include <rtdevice.h>
#include "device.h"

struct qx_spi_board_config{
    const char* name;
    volatile struct COMBINE_REGS* instance;
    INTERRUPT_Type intr_type;
    rt_uint32_t sck_pin;
    rt_uint32_t mosi_pin;
    rt_uint32_t miso_pin;
    rt_uint32_t cs_pin;
#if defined(RT_SPI_USING_DMA)
    DMA_ConfigParams* spi_rx_dma;
    DMA_ConfigParams* spi_tx_dma;
    rt_uint8_t rx_channel;
    rt_uint8_t tx_channel;
#endif
};

struct qx_spi_t{
    struct qx_spi_board_config* board_config;
    struct rt_spi_configuration *cfg;
    struct rt_spi_bus spi_bus;
#if defined(RT_SPI_USING_DMA)
    rt_uint16_t spi_dma_flag;
#endif
};

rt_err_t rt_hw_spi_init(void);
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);

int rt_soft_spi_init(void);
rt_err_t rt_sf_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t pinnum);

#endif
